import { Component, OnInit } from '@angular/core';
import { HttpService } from '../http.service';
import { UserService } from '../user.service';
import { Http } from '@angular/http';
import * as ons from 'onsenui';



@Component({
  selector: 'app-draw-money',
  templateUrl: './draw-money.component.html',
  styleUrls: ['./draw-money.component.less']
})
export class DrawMoneyComponent implements OnInit {
  count: any = '';
  uploading: boolean = false;

  constructor(private http: HttpService, private user: UserService) {
    this.user.getUserInfo();
  }

  get userInfo() {
    return this.user.userInfo.data;
  }

  drawAll(){
    this.count = this.userInfo.last_month_profit;
    this.draw();
  }

  async draw(){
    this.uploading = true;
    const {success, msg} = await this.http.post({
      name:'car.withdraw.score',
      withdraw_score: this.count
    })
    if(success) {
      ons.notification.toast('提取成功!', {timeout: 2000});
      this.user.userInfo.data.last_month_profit -= this.count;
      this.count = 0;
    } else {
      ons.notification.toast(msg, {timeout: 2000});
    }
    this.uploading = false;
  }

  ngOnInit() {
  }

}
